import { message } from 'antd'
import { MessageType } from 'antd/lib/message'

/* loading动画 */
let loader:MessageType

export const showLoading = (text:string = '加载中...') => {
  loader = message.loading(text, 0)
}
export const hideLoading = () => {
  loader && loader()
}

/**
 * 确认执行
 * @param text 确认文字
 * @param success 成功回调
 * @param cancel 取消回调
 */
export const $confirm = (text:string, success: CallableFunction, cancel?:CallableFunction) => {
  const res = confirm(text)

  if (res) {
    success()
  } else {
    cancel && cancel()
  }
}
